|
|
|
|
|
|
|
Programming with Palettes |
|
|
|
|
|
|
|
|
Palette indexes and palette-relative colors give you a great deal of control over how colors are used in an image. The easiest way to gain control is to load an image that contains the palette you want to use. Then you can erase the image's pixels and draw using the colors defined by the image's palette. |
|
|
|
|
|
|
|
|
Example program PalDraw, shown in Figure 3.8, lets you use all the colors available in an image's palette. Select Open from the program's File menu and select a bitmap file. The program loads that file and its color palette. |
|
|
|
|
|
|
|
|
Click on the ForeColor and FillColor boxes to select colors from the image's color palette. Click the Clear button to erase the picture using the FillColor you have selected. Use the program's combo boxes to determine the program's other drawing attributes. Then click and drag on the picture to draw shapes using the colors you have selected. |
|
|
|
|
|
|
|
|
Getting Palette Information |
|
|
|
|
|
|
|
|
There are several API functions that provide information for working with color palettes. The GetDeviceCaps function returns data about your computer's display. This information includes the display type (plotter, raster screen, and so forth), the size of the display, and whether the device can rotate text 90 degrees. Take a look at the online help for a complete list of this function's abilities. |
|
|
|
|
|
|
|
|
GetDeviceCaps takes as parameters a device context and a flag indicating the kind of information you want to retrieve. If you use the RASTERCAPS flag, the function returns a long integer containing the sum of several possible values. One of the more important values when you want to manipulate palettes is RC_PALETTE. If this flag is set, the device is using palettes. If it is not, you may as well not bother with palettes because the device will not support them. You can use the following code to see if a display device supports palettes and end your program if it does not. |
|
|
|
 |
|
|
|
|
Const RASTERCAPS = 38 ' Raster device capabilities.
Const RC_PALETTE = &H100 ' Has palettes. |
|
|
|
|
|
|
|
|
Figure 3.8
Example program PalDraw lets you draw using
the colors in an image's palette. |
|
|
|
|
|